import math
import threading

import cv2

from HUD.HUD_deal2 import HUD


class HUD_control:
    def __init__(self):
        self.HUD_deal = HUD()
        self.HUD_deal.setBt(70)

    def start_show(self):
        show_thread = threading.Thread(target=self.show)
        show_thread.start()

    def show(self):
        while True:
            if self.HUD_deal.d_img is not None:
                cv2.imshow('HUD', self.HUD_deal.d_img)
                cv2.waitKey(1)

    def set_msg(self, msg):
        if msg is not None:
            self.HUD_deal.setBt(int(msg[18]))
            self.HUD_deal.setAng(int(msg[10]))
            self.HUD_deal.setRoll(msg[9])
            self.HUD_deal.setPitch(msg[8])
            self.HUD_deal.setAltitude(msg[16])
            self.HUD_deal.setSpeed(int(
                math.sqrt(msg[11] * msg[11] + msg[12] * msg[12] + msg[13] * msg[13])))

    def set_img(self, img):
        if img is not None:
            self.HUD_deal.set_img(img)
            self.HUD_deal.add_attitude()

    def get_deal_img(self):
        return self.HUD_deal.get_output()
